import requests
from bs4 import BeautifulSoup

login_url = "https://itra.run/Account/Login"
session = requests.Session()
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
    "Referer": login_url,
}
response = session.get(login_url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
token_input = soup.find("input", {"name": "__RequestVerificationToken"})
if not token_input:
    raise Exception("无法找到 __RequestVerificationToken")
token = token_input["value"]
print("Token:", token)
payload = {
    "Input.Email": "465144122@qq.com",
    "Input.Password": "ChmLzj@123",
    "__RequestVerificationToken": token
}
post_headers = headers.copy()
post_headers["Content-Type"] = "application/x-www-form-urlencoded"
login_response = session.post(login_url, data=payload, headers=post_headers, allow_redirects=True)
print("状态码:", login_response.status_code)
status_code = login_response.status_code;
if (status_code == 200):
    cookies = session.cookies.get_dict()
    asp_session = cookies.get(".AspNetCore.Session")
    asp_identity = cookies.get(".AspNetCore.Identity.Application")
    print("AspNetCore.Session =", asp_session)
    print(".AspNetCore.Identity.Application =", asp_identity)
    auth_url = "https://zhizhangcs.cn/saveauth.php"
    post_data = {
        "session": asp_session,
        "application": asp_identity
    }
    auth_response = requests.post(auth_url, data=post_data)
    print("php 返回：", auth_response.status_code)
    print(auth_response.text)
